#include "ee.h"

void setType(EE *ee, EEType type) {
	if (type == EE_NULL) {
		ee->type = EE_TYPE_DEFAULT;
	} else {
		ee->type = type;
	}
}

EEType getType(EE* ee) {
	return ee->type;
}

void setMatrix(EE* ee, EEType type) {
	int i, j;
	if (type == EE_NULL) {
		setType(ee, EE_NULL);
	} else {
		setType(ee, type);

		switch (type) {
		case EE_QUADRADO3X3:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					ee->Matrix[i][j] = 255;
				}
			}
			break;
		case EE_CRUZ3X3:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					if ((i == 1) || (j == 1)) {
						ee->Matrix[i][j] = 255;
					} else {
						ee->Matrix[i][j] = 0;
					}
				}
			}
			break;

		case EE_VERTICAL3X3:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					if (j == 1) {
						ee->Matrix[i][j] = 255;
					} else {
						ee->Matrix[i][j] = 0;
					}
				}
			}
			break;

		case EE_HORIZONTAL3X3:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					if (i == 1) {
						ee->Matrix[i][j] = 255;
					} else {
						ee->Matrix[i][j] = 0;
					}
				}
			}
			break;

		case EE_DIAGONALPRI3X3:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					if (i == j) {
						ee->Matrix[i][j] = 255;
					} else {
						ee->Matrix[i][j] = 0;
					}
				}
			}
			break;

		case EE_DIAGONALSEC3X3:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					if (i + j == 2) {
						ee->Matrix[i][j] = 255;
					} else {
						ee->Matrix[i][j] = 0;
					}
				}
			}
			break;
		default:
			ee->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
			for (i = 0; i < 3; i++) {
				ee->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
			}
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					ee->Matrix[i][j] = 255;
				}
			}
			break;
		}
	}
}

pixel** getMatrix(EE* ee) {
	return ee->Matrix;
}

void print(EE* ee) {
	printf("Type:\t%d\n", getType(ee));
	printf("Matrix:\n");
	char i, j;

	pixel** EE1 = getMatrix(ee);
	
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 2; j++) {
			printf("%d\t", EE1[i][j]);
		}
		printf("%d\n", EE1[i][2]);
	}
	printf("====================\n\n");
}

/*int main(int argc, char **argv) {
	int aux;
	EEType type = EE_TYPE_DEFAULT;
	EE* ee;
		
	for (aux = 1; aux < argc; ++aux) {
		ee = (EE*)malloc(sizeof(struct structEE));
		setType(ee, atoi(argv[aux]));
		setMatrix(ee, getType(ee));
		print(ee);
		free(ee);
	}
	exit(0);
}*/

